package com.yuerlive.rainbow.module.live;

import android.provider.Telephony;
import android.support.v7.widget.RecyclerView;

import com.wuxiaolong.pullloadmorerecyclerview.PullLoadMoreRecyclerView;
import com.yuerlive.rainbow.R;
import com.yuerlive.rainbow.base.BaseActivity;
import com.yuerlive.rainbow.entity.ContributionData;
import com.yuerlive.rainbow.entity.User;
import com.yuerlive.rainbow.module.live.adapter.ContributionsAdapter;
import com.yuerlive.rainbow.module.live.presenter.ContributionContract;
import com.yuerlive.rainbow.module.live.presenter.ContributionPresenter;
import com.yuerlive.rainbow.module.recharge.core.wxpay.utils.MD5Util;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by xiaoyi on 2017/6/14.
 */

public class ContributionsActivity extends BaseActivity<ContributionContract.Presenter> implements ContributionContract.View {
    @BindView(R.id.recycleView)
    PullLoadMoreRecyclerView recyclerView;
    List<ContributionData> mDatas = new ArrayList<>();
    ContributionsAdapter adapter;
    String userId;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_contributions;
    }

    @Override
    protected void initViews() {
        setTitle("贡献榜");
        presenter = new ContributionPresenter(this);
        userId = getIntent().getStringExtra("upUserId");
        presenter.getContributionList(userId, true);
        recyclerView.setLinearLayout();
        recyclerView.setColorSchemeResources(R.color.colorPrimary);

        recyclerView.setOnPullLoadMoreListener(new PullLoadMoreRecyclerView.PullLoadMoreListener() {
            @Override
            public void onRefresh() {
                mDatas.clear();
                presenter.refresh(userId);
            }

            @Override
            public void onLoadMore() {
                mDatas.clear();
                presenter.refresh(userId);
            }
        });

        recyclerView.setPushRefreshEnable(false);

        adapter = new ContributionsAdapter(this, mDatas);
        recyclerView.setAdapter(adapter);

    }


    @Override
    public void setPresenter(ContributionContract.Presenter presenter) {
        this.presenter = presenter;
    }

    @Override
    public void showLoading() {
        recyclerView.setRefreshing(true);
    }

    @Override
    public void hideLoading() {
        recyclerView.setPullLoadMoreCompleted();
    }

    @Override
    public void showContributionList(List<ContributionData> datas, boolean loadMore) {
        mDatas.addAll(datas);
        adapter.notifyDataSetChanged();
    }
}
